import { iqiRequest as request} from '@/utils/request';
import { stringify } from 'qs';

export async function createDataSet(params) {
  return await request('/ad-hub/cv_datasets', {
    method: 'POST',
    data: params,
  });
}

// 创建数据集-添加图片 平台导入
export async function updateDataSetPath(params) {
  return await request(`/ad-hub/cv_datasets/cv_dataset_import_img`, {
    method: 'POST',
    data: params,
  });
}

// 创建数据集-添加图片 网页上传
export async function updateDataSetPathByUplaod(params) {
  return await request(`/ad-hub/cv_datasets/cv_dataset_upload`, {
    method: 'POST',
    data: params,
  });
}

// 查看图片-添加图片 网页上传
export async function addImagesByUpload(params) {
  return await request(`/ad-hub/cv_datasets/add_images_by_upload`, {
    method: 'POST',
    data: params,
  });
}

// 查看图片-添加图片 网页上传
export async function addImagesByPath(params) {
  return await request(`/ad-hub/cv_datasets/add_images_by_path`, {
    method: 'POST',
    data: params,
  });
}


// 创建数据集-添加图片 原始数据-条件筛选
export async function updateDataSetByCondition(params) {
  return await request(`/ipc/raw_images/make/condition`, {
    method: 'POST',
    data: params,
  });
}

// 创建数据集-添加图片 原始数据-手动选择
export async function updateDataSetByKeys(params) {
  return await request(`/ipc/raw_images/make/file_list`, {
    method: 'POST',
    data: params,
  });
}

// 查看图片-添加图片 原始数据-条件筛选
export async function addImagesByCondition(params) {
  return await request(`/ipc/raw_images/add/condition`, {
    method: 'POST',
    data: params,
  });
}

// 查看图片-添加图片 原始数据-手动选择
export async function addImagesByKeys(params) {
  return await request(`/ipc/raw_images/add/file_list`, {
    method: 'POST',
    data: params,
  });
}

export async function fetchDataSet(params) {
  return await request(`/ad-hub/cv_datasets?${stringify(params)}`);
}

export async function editDataSet(params) {
  return await request(`/ad-hub/cv_datasets/id/${params.id}/modification`, {
    method: 'POST',
    data: params,
  });
}

export async function cropDataSet(params) {
  return await request(`/ad-hub/dataset_jobs/crop/image`, {
    method: 'POST',
    data: params,
  });
}

export async function delDataSet(params) {
  return await request(`/ad-hub/cv_datasets/id/${params.id}`, {
    method: 'DELETE',
    data: params,
  });
}

// 删除当前数据集所有版本
export async function delDataSetVersions(params) {
  return await request(`/ad-hub/cv_datasets`, {
    method: 'DELETE',
    data: params,
  });
}

export async function getLabelScenes() {
  return await request(`/ad-hub/info/cv_annotation_scene`);
}

export async function getLabelType() {
  return await request(`/ad-hub/info/cv_annotation_types`);
}

// 根据标注类型获取数据集格式
export async function getDataSetFormat(params) {
  return await request(`/ad-hub/cv_datasets/map_type_to_format?${stringify(params)}`);
}

export async function fetchDataSetDetail(params) {
  return await request(`/ad-hub/cv_datasets/id/${params.id}`);
}

// 已创建标注任务的数据集查看图片
export async function fetchImgs(params) {
  return await request(`/ad-magic/image-annots/task/${params.id}/annots?${stringify({ ...params, id: undefined })}`);
}

// 未创建标注任务的数据集查看图片
export async function fetchImgsByDataSetId(params) {
  return await request(`/ad-magic/images/dataset/${params.id}?${stringify(params)}`);
}

// 已创建标注任务的数据集删除图片
export async function delImgs(params) {
  return await request(`/ad-magic/images`, {
    method: 'DELETE',
    data: params,
  });
}

// 未创建标注任务的数据集删除图片
export async function delImgsByImgIds(params) {
  return await request(`/ad-magic/images/dataset/${params.id}`, {
    method: 'DELETE',
    data: {
      ...params,
      id: undefined,
    },
  });
}

export async function createTask(params) {
  return await request(`/ad-magic/image-subtasks/selectiveCreate`, {
    method: 'POST',
    data: params,
  });
}

export async function releaseDataSet(params) {
  return await request(`/ad-hub/cv_datasets/publish_cv_dataset`, {
    method: 'POST',
    data: params
  });
}

export async function getLabelStatus() {
  return await request(`/ad-hub/info/cv_annotation_status`);
}

export async function getCreateSourceType() {
  return await request(`/ad-hub/info/source_types_creation`);
}

export async function getListSourceType() {
  return await request(`/ad-hub/info/source_types_display`);
}

export async function getCreateStatus() {
  return await request(`/ad-hub/info/cv_dataset_statues`);
}

export async function segmentDataSet(params) {
  return await request(`/ad-hub/cv_datasets/split_cv_dataset`, {
    method: 'POST',
    data: params,
  });
}

export async function downloadDataSet(params) {
  return await request('/ad-hub/cv_datasets/download_cv_dataset', {
    method: 'POST',
    data: params,
  });
}

export async function getTaskIdByDataSetId(params) {
  return await request(`/ad-magic/image-sets/dataset/${params.id}/get-task`);
}

export async function delAnnoTask(params) {
  return await request(`/ad-magic/image-tasks/${params.id}`, {
    method: 'DELETE',
  });
}

export async function downloadImages(params) {
  return await request('/ad-magic/tools/download-selected-task-images', {
    method: 'POST',
    data: params,
  });
}